package ro.bluecube.admlocal.persons.entity;

import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import ro.bluecube.admlocal.commons.PersistableEntity;
import ro.bluecube.admlocal.users.entity.User;

/**
 * @author anton
 *
 */
@Entity
@Table(name="persons")
@NamedQuery(name="findAllPersons", query="SELECT p FROM Person p")
public class Person extends PersistableEntity{

	private static final long serialVersionUID = 5296808594272892306L;
	
	private String firstName;
	private String lastName;
	private String email;

	private Collection<User> users;
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getEmail() {
		return email;
	}

	public void setUsers(Collection<User> users) {
		this.users = users;
	}

	@OneToMany(mappedBy="person", fetch=FetchType.EAGER, cascade={CascadeType.ALL})
	public Collection<User> getUsers() {
		return users;
	}
	
	@Override
	public String toString() {
		return getFirstName()+" "+getLastName();
	}
}